package com.blame.springblog;

import org.junit.jupiter.api.Test;
import org.springframework.util.DigestUtils;

import java.nio.charset.StandardCharsets;
import java.util.Random;
import java.util.UUID;

public class SecurityUtils {

    @Test
   public void s1(){
       String password="123456";
       //加盐
       String salt= UUID.randomUUID().toString().replace("-","");
       System.out.println(salt);
       //将加盐后的密码进行加密
       String securityPassword= salt+DigestUtils.md5DigestAsHex((salt+password).getBytes(StandardCharsets.UTF_8));
       System.out.println(securityPassword);

   }

   @Test
    public void check(){
        String securityPassword="1d0c281e26e54884b9b24d895a825feef2a5121191d3290fef27b687ed321507";
        String inputPassword="123456";
        String s=securityPassword.substring(0,32);  //截取前32个字符
        String result=DigestUtils.md5DigestAsHex((s+inputPassword).getBytes(StandardCharsets.UTF_8));
        System.out.println(securityPassword.equals(s+result));
   }
}
